package top.api.controller;



import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.service.CommonService;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;


@Slf4j
@RestController
@RequestMapping("/common")
@Api(tags = "公共接口")
@Validated
public class CommonController {

    @Autowired
    private CommonService commonService;


    /**
     * 生成bas64验证码
     * @param
     * @return
     */
    @GetMapping("/picCode")
    @ApiOperation("获取验证码bas64")
    public ResUlt picCode (){
        return commonService.getPicBas64();
    }

    @GetMapping("/checkPicCode")
    @ApiOperation("校验图片验证码")
    public ResUlt<Object> checkPicCode(@RequestParam @NotBlank(message = "验证码格式错误") String picCode, @RequestParam @Pattern(regexp = "^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$",message = "uuid格式错误") String uuid){
        return commonService.checkPicCode(picCode,uuid);
    }

}
